# -*- coding: utf-8 -*-

"""
@author: 陈列旺
@contact: QQ:55059
@Created on: 2021/9/16
@Remark:
"""
from backend.plugins.gc_pms_backend.models import PmsPrj
import uuid

from dvadmin.system.models import Dept
from dvadmin.utils.filters import DataLevelPermissionsFilter
from dvadmin.utils.json_response import SuccessResponse
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.viewset import CustomModelViewSet


class PmsPrjSerializer(CustomModelSerializer):
    """
    项目-序列化器
    """

    class Meta:
        model = PmsPrj
        fields = "__all__"
        read_only_fields = ["id"]


class PmsPrjCreateUpdateSerializer(CustomModelSerializer):
    """
    项目管理 创建/更新时的列化器
    """
    class Meta:
        model = PmsPrj
        fields = '__all__'


class PmsPrjViewSet(CustomModelViewSet):
    """
    项目管理接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = PmsPrj.objects.all()
    serializer_class = PmsPrjSerializer
    permission_classes = []

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True, request=request)
            return self.get_paginated_response(serializer.data)
        serializer = self.get_serializer(queryset, many=True, request=request)
        return SuccessResponse(data=serializer.data, msg="获取成功")
